#Boa:Dialog:Dialog1

import wx
import wx.grid
import consultasBD

def create(parent):
    return Dialog1(parent)

[wxID_DIALOG1, wxID_DIALOG1BUTTON1, wxID_DIALOG1GRID1, wxID_DIALOG1IDCLIENTE, 
 wxID_DIALOG1STATICTEXT1, 
] = [wx.NewId() for _init_ctrls in range(5)]

class Dialog1(wx.Dialog):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Dialog.__init__(self, id=wxID_DIALOG1, name='', parent=prnt,
              pos=wx.Point(229, 236), size=wx.Size(740, 312),
              style=wx.DEFAULT_DIALOG_STYLE,
              title='Historico de Saldos de Clientes')
        self.SetClientSize(wx.Size(724, 276))

        self.staticText1 = wx.StaticText(id=wxID_DIALOG1STATICTEXT1,
              label='Cliente ID:', name='staticText1', parent=self,
              pos=wx.Point(24, 8), size=wx.Size(52, 13), style=0)

        self.idcliente = wx.TextCtrl(id=wxID_DIALOG1IDCLIENTE, name='idcliente',
              parent=self, pos=wx.Point(80, 8), size=wx.Size(80, 21), style=0,
              value='')

        self.button1 = wx.Button(id=wxID_DIALOG1BUTTON1, label='Buscar',
              name='button1', parent=self, pos=wx.Point(176, 8),
              size=wx.Size(75, 23), style=0)
        self.button1.Bind(wx.EVT_BUTTON, self.OnButton1Button,
              id=wxID_DIALOG1BUTTON1)

        self.grid1 = wx.grid.Grid(id=wxID_DIALOG1GRID1, name='grid1',
              parent=self, pos=wx.Point(8, 40), size=wx.Size(704, 208),
              style=0)

    def __init__(self, parent):
        self._init_ctrls(parent)
        columnas =['IDRecibo','IDCliente   ',' Forma de Pago ','montopago ', '   	Descripcion     xxx             ']
        self.grid1.CreateGrid(30, len(columnas))
        
        for i, col in enumerate(columnas): 
            self.grid1.SetColLabelValue(i, col)
            
        self.grid1.AutoSizeColumn(0,True)
        self.grid1.AutoSizeRow(0,True)
        self.grid1.AutoSizeColumn(1,True)
        self.grid1.AutoSizeColumn(2,True)
        self.grid1.AutoSizeColumn(3,True)
        self.grid1.AutoSizeColumn(4,True)
        
        
        
        self.total = "" 
        

    def OnButton1Button(self, event):
        idcliente2 = str(self.idcliente.GetValue())
        
        SQL = "select * from vtas_valores where idcliente = '%s'" % (idcliente2)
        resultado = consultasBD.ordenCrudaDict(SQL)
        
                
        for i, r in enumerate(resultado):
            descri = ""
            
            if ("Pago saldo" not in str(r['descripcion'])):
                SQL2 = "select * from vtas_ctasctestienepagos  WHERE idrecibo = '%s'" % (r['idrecibo'])
                resultado1 = consultasBD.ordenCrudaDict(SQL2)
                for r1 in resultado1:
                    descri = str(r['descripcion'])+" Cta.Cte: "+ str(r1["fecha"])
                    self.grid1.SetCellValue(i, 4, str(descri))
            else:
                self.grid1.SetCellValue(i, 4, str(r['descripcion']))
            
        
            self.grid1.SetCellValue(i, 0, str(r['idrecibo']))
            self.grid1.SetCellValue(i, 1, str(r['idcliente']))
            self.grid1.SetCellValue(i, 2, str(r['idformapago']))
            self.grid1.SetCellValue(i, 3, str(r['montopago']))

        
